package com.xtx.controller.user;

import com.xtx.dto.AddShoppingCartDTO;
import com.xtx.entity.ShoppingCart;
import com.xtx.result.Result;
import com.xtx.service.ShoppingService;
import com.xtx.vo.ShoppingCartVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/shopping/cart")
@RestController
@Slf4j
public class ShoppingController {

    @Autowired
    private ShoppingService shoppingService;

    @PostMapping
    public Result addShoppingCart(@RequestBody AddShoppingCartDTO addShoppingCartDTO){
        shoppingService.addShoppingCart(addShoppingCartDTO);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result<List<ShoppingCartVO>> getShoppingCartList(@PathVariable Integer id){
        return Result.success(shoppingService.getShoppingCartList(id));
    }
    @DeleteMapping("/{id}")
    public Result deleteShoppingCart(@PathVariable Integer id){
        shoppingService.deleteShoppingCart(id);
        return Result.success();
    }
    @PutMapping
    public Result updateShoppingCart(@RequestBody ShoppingCart shoppingCart){
        shoppingService.updataShoppingCart(shoppingCart);
        return Result.success();
    }
    @PutMapping("/{userId}")
    public Result checkAll(@PathVariable Integer userId,@RequestBody ShoppingCart shoppingCart){
        shoppingService.checkAll(userId,shoppingCart);
        return Result.success();
    }
}
